//------------------------------------------------------------------------
// Abstract: Define Singleton Patterns class/macro
//
// Authoring: XiaoHanxiong
//
// Time: 2014.03.09
//
// Static test:
//
// Version history:
//		Ver_1.0 : 2014.03.09	XiaoHanxiong
//------------------------------------------------------------------------
#ifndef _Library_Singleton_h_
#define _Library_Singleton_h_

#include "Stdafx.h"


/* Define Singleton Macro */
#define INITIALIZE_SINGLETON_CLASS_INSTANCE(ClassName)\
	ClassName *ClassName::m_this = NULL

#define GET_SINGLETON_CLASS_INSTANCE(ClassName)\
	ClassName::getUniqueInstance()

#define GET_SINGLETON_CLASS_INSTANCE_PTR(ClassName)\
	ClassName::getUniqueInstancePtr()

#define RELEASE_SINGLETON_CLASS_INSTANCE(ClassName)\
	ClassName::releaseUniqueInstance()

#define ANNOUNCEMENT_SINGLETON_CLASS(ClassName, Constructor, Destructor)\
private:\
	static ClassName* m_this;\
private:\
	ClassName()\
	{\
		Constructor();\
	}\
	~ClassName()\
	{\
		Destructor();\
	}\
public:\
	static ClassName* getUniqueInstancePtr()\
	{\
		if(!m_this) m_this = new ClassName();\
		return m_this;\
	}\
	static ClassName& getUniqueInstance()\
	{\
		if(!m_this) m_this = new ClassName();\
		return (*m_this);\
	}\
	static void releaseUniqueInstance()\
	{\
		if(m_this) delete m_this;\
		m_this = NULL;\
	}\
public:

/* Define the Operation Macro as a Function Call */
#define InitializeSingletonClass(ClassName) INITIALIZE_SINGLETON_CLASS_INSTANCE(ClassName)
#define GetUniqueInstance(ClassName)		GET_SINGLETON_CLASS_INSTANCE(ClassName)
#define GetUniqueInstancePtr(ClassName)		GET_SINGLETON_CLASS_INSTANCE_PTR(ClassName)
#define ReleaseUniqueInstance(ClassName)	RELEASE_SINGLETON_CLASS_INSTANCE(ClassName)


#endif